Skip to content

Intrinsify typeof().Assembly.GetType()#127697

Closed
am11 wants to merge 1 commit intodotnet:mainfrom
am11:feature/intrinsify-typeof.assembly.gettype
Closed

Intrinsify typeof().Assembly.GetType()#127697
am11 wants to merge 1 commit intodotnet:mainfrom
am11:feature/intrinsify-typeof.assembly.gettype

Conversation

@am11
Copy link
Copy Markdown
Member

@am11 am11 commented May 4, 2026

DOTNET_JitFoldAssemblyGetType=0

G_M43549_IG01:  ;; offset=0x0000
            stp     fp, lr, [sp, #-0x10]!
            mov     fp, sp
                                                ;; size=8 bbWeight=1 PerfScore 1.50
G_M43549_IG02:  ;; offset=0x0008
            movz    x0, #0x2328
            movk    x0, #0x778 LSL #16
            movk    x0, #1 LSL #32
            bl      System.RuntimeTypeHandle:GetAssemblyIfExists(System.RuntimeType):System.Reflection.RuntimeAssembly
            cbz     x0, G_M43549_IG05
                                                ;; size=20 bbWeight=1 PerfScore 3.50
G_M43549_IG03:  ;; offset=0x001C
            movz    x1, #0x2350
            movk    x1, #0x778 LSL #16
            movk    x1, #1 LSL #32
            ldr     x2, [x0]
            ldr     x2, [x2, #0x58]
            ldr     x2, [x2, #0x38]
            blr     x2      // code for System.Reflection.Assembly:GetType(System.String):System.Type:this
                                                ;; size=28 bbWeight=1 PerfScore 11.50
G_M43549_IG04:  ;; offset=0x0038
            ldp     fp, lr, [sp], #0x10
            ret     lr
                                                ;; size=8 bbWeight=1 PerfScore 2.00
G_M43549_IG05:  ;; offset=0x0040
            movz    x0, #0x2328
            movk    x0, #0x778 LSL #16
            movk    x0, #1 LSL #32
            movz    x1, #0x11B8      // code for System.RuntimeTypeHandle:<GetAssembly>g__GetAssemblyWorker|43_0(System.RuntimeType):System.Reflection.RuntimeAssembly
            movk    x1, #732 LSL #16
            movk    x1, #1 LSL #32
            ldr     x1, [x1]
            blr     x1      // code for System.RuntimeTypeHandle:<GetAssembly>g__GetAssemblyWorker|43_0(System.RuntimeType):System.Reflection.RuntimeAssembly
            b       G_M43549_IG03
                                                ;; size=36 bbWeight=0.01 PerfScore 0.08

; Total bytes of code 100, prolog size 8, PerfScore 18.58, instruction count 25, allocated bytes for code 100 (MethodHash=f08955e2) for method C:GetOtherType():System.Type:this (FullOpts)
; ============================================================

DOTNET_JitFoldAssemblyGetType=1

G_M43549_IG01:  ;; offset=0x0000
            stp     fp, lr, [sp, #-0x10]!
            mov     fp, sp
                                                ;; size=8 bbWeight=1 PerfScore 1.50
G_M43549_IG02:  ;; offset=0x0008
            movz    x0, #0xA328
            movk    x0, #0x94E LSL #16
            movk    x0, #1 LSL #32
                                                ;; size=12 bbWeight=1 PerfScore 1.50
G_M43549_IG03:  ;; offset=0x0014
            ldp     fp, lr, [sp], #0x10
            ret     lr
                                                ;; size=8 bbWeight=1 PerfScore 2.00

; Total bytes of code 28, prolog size 8, PerfScore 5.00, instruction count 7, allocated bytes for code 28 (MethodHash=f08955e2) for method C:GetOtherType():System.Type:this (FullOpts)
; ============================================================

AOT defaults to DOTNET_JitFoldAssemblyGetType=1.

@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label May 4, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label May 4, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@jkotas
Copy link
Copy Markdown
Member

jkotas commented May 4, 2026

This does not work for multiple reasons. One of the problems is that Assembly.GetType can return different results depending on the context - see remarks in https://learn.microsoft.com/en-us/dotnet/api/system.reflection.assembly.gettype?view=net-10.0#remarks.

Also, it would break instrumentation #126831 that we plan to add to these APIs.

@am11 am11 force-pushed the feature/intrinsify-typeof.assembly.gettype branch from 31f90cb to 2f44fcf Compare May 4, 2026 14:31
@am11
Copy link
Copy Markdown
Member Author

am11 commented May 4, 2026

Ah, you're right, this can't work as a JIT intrinsic. Assembly.GetType semantics depend on runtime state (caller's AssemblyLoadContext, contextual reflection context, type forwarders, observable load-failure exceptions) that the JIT can't reason about. Folding at JIT time would diverge from runtime behavior in any of those cases. This was just an experiment, closing the PR. Thanks for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants